/**
 * Copyright @ 2023 iAuto (Shanghai) Co., Ltd.
 * All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are NOT permitted except as agreed by
 * iAuto (Shanghai) Co., Ltd.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 */

// 声明基础
export interface IStatus {
  statusCode: string;
  statusMessage: string;
}

// 声明正常返回值类型
export interface IResponse<T = any> extends IStatus {
  data: T;
}

// 声明正常返回值类型
export interface IResponseList<T = any> extends IStatus {
  data: {
    dataList: T;
    itemSize: number; // 返回的数据条数
    pageNo: number;
    pageSize: number;
    pageCount: number; // 总条数
  };
}

// 声明分页通用参数
export type IAntdTablePageParams = {
  current: number;
  pageSize: number;
};

export interface IAntdTableParams extends IAntdTablePageParams {
  filter?: any;
  sorter?: any;
  extra?: any;
}

// 声明返回值promise类型，用于定义请求
export type IPromiseApi<T> = Promise<IResponse<T>>;
export type IPromiseListApi<T> = Promise<IResponseList<T>>;

export type IPromiseError = Promise<IStatus & { data: unknown }>;

// 基础服务api
export interface BaseApiResponse<T = any> {
  error: {
    code?: string | number;
    statusCode?: string | number;
    message?: string;
    statusMessage?: string;
  };
  data: T;
  pageable?: {
    pageNumber: number;
    pageSize: number;
    total: number;
  };
}

export type NewBaseApiResponse = BaseApiResponse & IStatus;

export enum Methods {
  POST = 'POST',
  GET = 'GET',
  DELETE = 'DELETE',
  PUT = 'PUT',
}

export type ResponseResult<T = unknown> = {
  statusCode: string;
  statusMessage: string;
  data: T;
};

export type ListType<T = unknown> = {
  list: T[];
  pagination: {
    current: number;
    pageSize: number;
    total: number;
  };
};
